use tokio::sync::mpsc;

#[tokio::test]
async fn test_single_mpsc_channel() {
    let (tx, mut rx) = mpsc::channel(100);

    tokio::spawn(async move {
        for i in 0..10 {
            if let Err(err) = tx.send(i).await {
                println!("receiver dropped: {:?}", err);
                return;
            }
        }
    });

    while let Some(i) = rx.recv().await {
        println!("got: {}", i);
    }
}

#[tokio::test]
async fn test_mult_mpsc_channel() {
    let (tx, mut rx) = mpsc::channel(100);

    let tx1 = tx.clone();

    tokio::spawn(async move {
        for i in 0..10 {
            if let Err(err) = tx.send(i).await {
                println!("receiver dropped: {:?}", err);
                return;
            }
        }
    });

    tokio::spawn(async move {
        for i in 90..100 {
            if let Err(err) = tx1.send(i).await {
                println!("receiver dropped: {:?}", err);
                return;
            }
        }
    });

    while let Some(i) = rx.recv().await {
        println!("got: {}", i);
    }
}
